from functools import cached_property

from webutils.layers.managers import EnumMixin
from webutils.layers.managers.redis import (KeyValueMixin, SetMixin, ZsetMixin)

from .. import const
from .base import BaseManager


class UserInfo(KeyValueMixin, BaseManager):
    required_context = ['room_id', 'user_id']

    @cached_property
    def key(self):
        return self.get_redis_key('user', self.room_id, self.user_id)


class UserOnlineStage(EnumMixin, KeyValueMixin, BaseManager):
    required_context = ['room_id', 'user_id']
    enum_class = const.OnlineStage

    @cached_property
    def key(self):
        return self.get_redis_key('online', self.room_id, self.user_id)


class GroupCounter(ZsetMixin, BaseManager):
    @cached_property
    def zset_key(self):
        return self.get_redis_key('online', self.room_id)


class ProxyUserCounter(SetMixin, BaseManager):
    required_context = ['room_id', 'proxy_id']

    @cached_property
    def set_key(self):
        return self.get_redis_key('online', 'proxy', self.room_id,
                                  self.proxy_id)
